package com.aaa.tmr.controller;

import com.aaa.tmr.entity.Progress;
import com.aaa.tmr.service.ProgressService;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;
import com.github.pagehelper.PageInfo;
import com.aaa.tmr.util.Result;
import com.aaa.tmr.util.ReturnStatus;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

/**
 * (Progress)表控制层
 *
 * @author makejava
 * @since 2021-03-24 18:39:07
 */
@Controller
@RequestMapping("progress")
public class ProgressController {
    /**
     * 服务对象
     */
    @Resource
    private ProgressService progressService;
    @Resource
    private HttpSession session;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @ResponseBody
    @RequestMapping("selectOne")
    public Progress selectOne(Integer id) {
        return this.progressService.queryById(id);
    }

    /**
     * 跳转部门分页列表页面
     *
     * @return
     */
    @RequestMapping("toProgress")
    public String toPage() {
        return "back/progress-page";
    }
    /**
     * 跳转到进度图表分析页面
     * @return
     */

    @RequestMapping("toProgressEchart")
    public String toPageEchart() {
        return "back/progressEchart";
    }
    /**
     * 分页查询方法
     *
     * @param page
     * @param limit
     * @param progress
     * @return
     */
    @ResponseBody
    @RequestMapping("queryAll")
    public Result queryAll(Integer page, Integer limit, Progress progress) {
        PageInfo pageInfo = progressService.queryAll(page, limit, progress);
        return new Result(ReturnStatus.SUCCESS.getCode(), ReturnStatus.SUCCESS.getMessage(),
                pageInfo.getTotal(), pageInfo.getList());
    }


    /**
     * 部门添加
     *
     * @param progress
     * @return
     */
    @ResponseBody
    @PostMapping("insert")
    public Result insert(Progress progress) {
        return new Result(ReturnStatus.SUCCESS.getCode(), ReturnStatus.SUCCESS.getMessage(),
                0, progressService.insert(progress));
    }

    /**
     * 部门更新
     *
     * @param progress
     * @return
     */
    @ResponseBody
    @PutMapping("update")
    public Result update(Progress progress) {
        return new Result(ReturnStatus.SUCCESS.getCode(), ReturnStatus.SUCCESS.getMessage(),
                0, progressService.update(progress));
    }

    /**
     * 通过主键删除数据
     *
     * @param progressId 主键
     * @return 是否成功
     */
    @ResponseBody
    @DeleteMapping("deleteById")
    public Result deleteById(Integer progressId) {
        return new Result(ReturnStatus.SUCCESS.getCode(),
                ReturnStatus.SUCCESS.getMessage(), 0,
                this.progressService.deleteById(progressId));
    }


    /**
     * 通过主键删除数据
     *
     * @param progressIds 主键
     * @return 是否成功
     */
    @ResponseBody
    @DeleteMapping("deleteByIds")
    public Result deleteByIds(String progressIds) {
        return new Result(ReturnStatus.SUCCESS.getCode(),
                ReturnStatus.SUCCESS.getMessage(), 0,
                this.progressService.batchDeleteById(progressIds));
    }
    /**
     * 按年月查询图标显示数据
     * @param year
     * @param month
     * @return
     */
    @ResponseBody
    @RequestMapping("queryShowChartData")
    public Result queryShowChartData(Integer year, Integer month) {
        return new Result(ReturnStatus.SUCCESS.getCode(),
                ReturnStatus.SUCCESS.getMessage(), 0,
                this.progressService.queryShowChartData(year,month));
    }


}
